package com.javatest.springboot3minio.controller.convertor;

import com.javatest.springboot3minio.dto.AttachmentInfoDto;
import com.javatest.springboot3minio.entity.AttachmentInfo;
import com.javatest.springboot3minio.utils.MinioFileUtil;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA. Description:
 *
 * @author lzy
 * @since 2024-01-12 下午2:37
 */
@Component
public class AttachmentDtoConvertor implements BiConvertor<AttachmentInfoDto, AttachmentInfo> {
  /**
   * @param domain the domain
   * @return
   */
  @Override
  public AttachmentInfoDto getDtoFromDo(AttachmentInfo domain) {
    AttachmentInfoDto dto = new AttachmentInfoDto();
    dto.setId(domain.getId());
    dto.setAttachmentName(domain.getAttachmentName());
    dto.setAttachmentType(domain.getAttachmentType());
    dto.setProjectId(domain.getProjectId());
    dto.setAttachmentUrl(
        MinioFileUtil.getFilePreviewUrl(domain.getProjectId(), domain.getAttachmentName())
            .orElse("#"));
    return dto;
  }
}
